/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.pps.web.bean.teacher;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ReverseComparator;
import vn.com.pps.entities.Teacher;
import vn.com.pps.web.common.component.table.LazyCacheModel;
import vn.com.pps.web.ui.CourseTeacherTableItem;

/**
 *
 * @author Hieu
 */
public class CourseTeacherBean extends LazyCacheModel implements Serializable {

    private ArrayList<CourseTeacherTableItem> courseTeacherTableItems;
    private int rowCount = 0;
    private int teacherID = 0;
    private Teacher teacher;
    

    @Override
    protected void init() {
//        rowCount = getServiceLocator().getCourseService().countCourse("TeacherID=" + teacherID);
//        setTargetPage(1);
//        setRowCount(rowCount);
//        courseTeacherTableItems = getServiceLocator().getCourseService().getTeacherByCourse(getTargetPage(), getMaximumPageSize(), teacherID);
//        setPageItems(courseTeacherTableItems);
    }

    @Override
    public void sort(String pm_column, boolean pm_ascending) {
        Comparator<CourseTeacherTableItem> bc = null;
        if (pm_ascending) {
            bc = new BeanComparator(pm_column);
        } else {
            bc = new BeanComparator(pm_column, new ReverseComparator(new ComparableComparator()));
        }
        Collections.sort(getPageItems(), bc);
    }

    @Override
    public void loadData() {
        System.out.println("TeacherID:"+teacherID);
        rowCount = getServiceLocator().getCourseService().getCountCoursesByTeacher(teacherID);
        setTargetPage(1);
        setRowCount(rowCount);
        courseTeacherTableItems = getServiceLocator().getCourseService().getCoursesByTeacher(getTargetPage(), getMaximumPageSize(), teacherID);
        setPageItems(courseTeacherTableItems);
    }

    public void setTeacherID(int teacherID) {
        System.out.println("@setTeacherID:"+teacherID);
        this.teacherID = teacherID;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }
    
}
